<template>
  <div class="app-container" style="margin-top: 90px;">

    <el-tabs v-model="editableTabsValue" type="border-card" 
    @tab-remove="removeTab" >
      <el-tab-pane
        label="会员查询"
        name="会员查询"
      >
        <div class="header">
          <div style="display: flex;flex-direction: column;justify-content: end;width: 60%;">
            <el-form :model="query" ref="query" label-width="80px">
              <el-row :gutter=10>
                <el-col :span=16>
                  <el-form-item label-width="250px" label="姓名/编号/电话(后四位)/身份证号" prop="name" >
                      <el-input v-model="query.name" placeholder="请输入姓名/编号/电话(后四位)/身份证号"/>
                  </el-form-item>
                </el-col>
                <el-col :span=8>
                  <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="search" >搜索</el-button>
                    <el-button @click="resetForm('query')">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>

          <!-- <el-card class="box-card" v-for="report in reports" :key="report.jobOfficeId"  >
            <div slot="header" class="clearfix">
              <span>{{ report.jobOfficeName }}</span>
            </div>
            <div class="text item">
              {{'候诊人数: ' + report.waitingCount }}
            </div>
            <div class="text item">
              {{'就诊人数: ' + report.doingCount }}
            </div>
          </el-card> -->
        </div>
        <el-table
          v-loading="patientListLoading"
          :data="patientList"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
        > 
          <el-table-column align="center" label="序号" width="50">
            <template slot-scope="scope">
              {{ scope.$index + 1 }}
            </template>
          </el-table-column>
          <el-table-column label="编号" width="120" align="center">
            <template slot-scope="scope">
              {{ scope.row.code }}
            </template>
          </el-table-column>
          <el-table-column label="姓名" width="100" align="center">
            <template slot-scope="scope">
              {{ scope.row.name }}
            </template>
          </el-table-column>
          <el-table-column label="手机号" width="80" align="center">
            <template slot-scope="scope">
              {{ scope.row.phone }}
            </template>
          </el-table-column>
          <el-table-column label="身份证号" width="170" align="center">
            <template slot-scope="scope">
              {{ scope.row.idCard }}
            </template>
          </el-table-column>
          <el-table-column label="性别" width="50" align="center">
            <template slot-scope="scope">
              {{ scope.row.sex }}
            </template>
          </el-table-column>
          <el-table-column label="出生年月" width="120" align="center">
            <template slot-scope="scope">
              {{ scope.row.birthday + ' ' }} {{ scope.row.birthdayType | birthdayTypeFilter }} 
            </template>
          </el-table-column>
          <el-table-column label="年龄" width="50" align="center">
            <template slot-scope="scope">
              {{ scope.row.age }}
            </template>
          </el-table-column>
          <el-table-column label="入籍时长" width="120" align="center">
            <template slot-scope="scope">
              {{ scope.row.joinDuration }}
            </template>
          </el-table-column>
          <el-table-column label="就诊状态" width="100" align="center">
            <template slot-scope="scope">
              {{ scope.row.visitStatus }}
            </template>
          </el-table-column>
          <el-table-column label="会员等级" width="80" align="center">
            <template slot-scope="scope">
              {{ scope.row.vipLevel?scope.row.vipLevel:'V0' }}
            </template>
          </el-table-column>
          <el-table-column label="就诊日期" width="130" align="center">
            <template slot-scope="scope">
              {{ scope.row.visitDate }}
            </template>
          </el-table-column>
          <el-table-column class-name="status-col" :label="'信息查询\n信息修改\n等级设置'" align="center" width="130" >
            <template slot-scope="scope">
              <el-button type="primary" @click="optionPatient(scope.row)">挂号操作</el-button>
              <!-- <el-dropdown size="medium" trigger="click" @command="optionPatient" >
                <el-button type="primary">
                  操作<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item :command="composeValue(scope.row, 1)" >基础信息查询</el-dropdown-item>
                  <el-dropdown-item :command="composeValue(scope.row, 2)" >基础信息修改</el-dropdown-item>
                  <el-dropdown-item :command="composeValue(scope.row, 3)" >会员等级设置</el-dropdown-item>
                  <el-dropdown-item :command="composeValue(scope.row, 4)" divided >会员就诊记录查询</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown> -->
              <!-- <el-button type="warning"  @click="toGuidance(scope.row)" size="small">挂号</el-button>
              <el-button type="primary"  @click="getInfo(scope.row)" size="small">详情</el-button>
              <el-button type="success"  @click="update(scope.row)" size="small">修改</el-button>
              <el-button type="danger" @click="deleteInfo(scope)" size="small">删除</el-button> -->
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          layout="->, total, prev, pager, next"
          :total="total"
          :current-page="currentPage"
          :page-size="pageSize"
          @current-change="clickCurPage"
          >
        </el-pagination>
      </el-tab-pane>
      <el-tab-pane
        v-for="item in editableTabs"
        :key="item.name"
        :label="item.title"
        :name="item.name"
        closable
        @tab-remove="removeTab"
      >
        <!-- patient detail -->
        <div>
          <el-container>
            <el-main>
              <el-row :gutter=10>
                  <el-col :span=24><span style="font-size: 16px;">就诊状态: 今日无就诊</span></el-col>
              </el-row>
              
              <el-tabs v-if="item.content.patientTabs && item.content.patientTabs.length != 0" v-model="item.content.patientTabsValue" type="border-card" closable @tab-remove="(targetName) => removePatientTab(targetName, item.content)">
                <el-tab-pane
                  v-for="patientTab in item.content.patientTabs"
                  :key="patientTab.name"
                  :label="patientTab.title"
                  :name="patientTab.name"
                >

                <div v-if="item.content.patientTabsValue == '会员管理'">
                  <el-form :model="item.content" label-width="120px" :rules="addPatientFormRules">
                    <el-row :gutter="10">
                      <!-- <el-col :span=8 >
                        <el-form-item label="编号">
                          <el-input v-model="addPatientForm.code" />
                        </el-form-item>
                      </el-col> -->
                      <el-col :span=8 >
                        <el-form-item label="姓名" prop="name">
                          <el-input v-model="item.content.name" :disabled="true" />
                        </el-form-item>
                      </el-col>
                      <el-col :span=6 >
                        <el-form-item label="性别" prop="sex">
                          <el-select v-model="item.content.sex" placeholder="请选择" :disabled="true" >
                            <el-option
                              v-for="item in sexEnum"
                              :key="item"
                              :label="item"
                              :value="item">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="10">
                      <el-col :span=6 >
                        <el-form-item label="手机号1" prop="phone">
                          <el-input v-model="item.content.phone" @input="inputPhone" maxlength="11" :disabled="true" />
                        </el-form-item>
                      </el-col>
                      <el-col :span=6 >
                        <el-form-item label="手机号2" >
                          <el-input v-model="item.content.phoneTwo" @input="inputPhone" maxlength="11" :disabled="true" />
                        </el-form-item>
                      </el-col>
                      <el-col :span=6 >
                        <el-form-item label="手机号3" >
                          <el-input v-model="item.content.phoneThree" @input="inputPhone" maxlength="11" :disabled="true" />
                        </el-form-item>
                      </el-col>
                      <el-col :span=6 >
                        <el-form-item label="身份证号" prop="idCard">
                          <el-input style="width: 100%" v-model="item.content.idCard" @input="inputIdCard" maxlength="18" :disabled="true" />
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="10">
                      <el-col :span=4 >
                        <el-form-item label="出生日期" prop="birthday">
                          <el-date-picker v-model="item.content.birthday" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" @change="changeBirthday" :disabled="true" ></el-date-picker>
                        </el-form-item>
                      </el-col>
                      <el-col :span=6 :offset=4>
                        <el-form-item label="农历/公历" prop="birthdayType">
                          <el-select v-model="item.content.birthdayType" placeholder="请选择" :disabled="true" >
                            <el-option
                              v-for="item in birthdayTypeEnum"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span=6 >
                        <el-form-item label="年龄">
                          <el-input v-model="item.content.age" type="Number" min=0  :disabled="true" />
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="10">
                      <el-col :span=8 >
                        <el-form-item label="来源" prop="source">
                          <el-select v-model="item.content.source" placeholder="请选择" :disabled="true" >
                            <el-option
                              v-for="item in sourceEnum"
                              :key="item.id"
                              :label="item.source"
                              :value="item.id"
                              >
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span=8 >
                        <el-form-item label="介绍人" v-if="item.content.source == 1 || item.content.source == 2" >
                          <el-select v-if="item.content.source == 1" v-model="item.content.introducer" placeholder="请选择" :disabled="true">
                            <el-option
                              v-for="item in patientEnum"
                              :key="item.id"
                              :label="item.code + ' - ' +item.name"
                              :value="item.id">
                            </el-option>
                          </el-select>
                          <el-select v-else-if="item.content.source == 2" v-model="item.content.introducer" placeholder="请选择" :disabled="true">
                            <el-option
                              v-for="item in userEnum"
                              :key="item.id"
                              :label="item.jobNumber + ' - ' + item.name"
                              :value="item.id">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <div style="width:100%;border: 2px solid #E4E7ED;padding: 10px;">
                      <div v-for="(address, index) in item.content.addressList" :key="index" >
                        <el-row :gutter="10" v-if="index != 0">
                          <el-col :span=6>
                            <el-form-item label="多址说明" prop="multiAddressDes">
                              <el-select v-model="address.multiAddressDes" placeholder="请选择" :disabled="true" >
                                <el-option
                                  v-for="item in multiAddressDesEnum"
                                  :key="item"
                                  :label="item"
                                  :value="item"
                                >
                                </el-option>
                              </el-select>
                            </el-form-item>
                          </el-col>
                          <el-col :span=6>
                            <el-form-item label="说明填写" v-if="address.isOtherAddress == 1" prop="multiAddressDesOther">
                              <el-input v-model="address.multiAddressDesOther" :disabled="true"/>
                            </el-form-item>
                          </el-col>
                        </el-row>
                        <el-row :gutter="10">
                          <el-col :span=8 >
                            <el-form-item label="省/市/区" prop="addressPre" >
                              <el-cascader
                                :disabled="true"
                                size="large"
                                :options="options"
                                v-model="address.addressPre"
                                :props="{ value: 'label', label: 'label'}"
                                >
                              </el-cascader>
                            </el-form-item>
                          </el-col>
                          <el-col :span=6>
                            <el-form-item label="小区" prop="addressMid">
                              <el-input v-model="address.addressMid" :disabled="true" ></el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span=10 >
                            <el-form-item label="详细地址" prop="addressInfo">
                              <el-input v-model="address.addressInfo" :disabled="true" ></el-input>
                            </el-form-item>
                          </el-col>
                        </el-row>
                        <el-row :gutter="10">
                          <el-col :span=8 >
                            <el-form-item label="距离" prop="retailStore">
                              <el-select v-model="address.retailStore" placeholder="门店请选择" :disabled="true" >
                                <el-option
                                  v-for="item in deptEnum"
                                  :key="item"
                                  :label="item"
                                  :value="item"
                                >
                                </el-option>
                              </el-select>
                            </el-form-item>
                          </el-col>
                          <el-col :span=8 >
                            <el-form-item label="公交站数" prop="distance">
                              <el-input v-model="address.distance" type="Number" min=0 :disabled="true" />
                            </el-form-item>
                          </el-col>
                        </el-row>
                        <el-divider></el-divider>
                      </div>
                    </div>
                  </el-form>
                </div>

                <div v-if="item.content.patientTabsValue == '挂号'">
                  <el-form ref="registerForm" :model="item.content.registerForm" label-width="120px"  class="guidance-form">
                    <el-row :gutter= 8>
                      <el-col :span=10>
                        <el-form-item label="就诊类型" prop="type">
                          <el-select v-model="item.content.registerForm.type" placeholder="请选择" >
                            <el-option
                              v-for="type in typeEnum"
                              :key="type.id"
                              :label="type.name"
                              :value="type.id"
                              @click.native="updateVisitType(type, item.content)"
                              >
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <el-col :span=6>
                        <el-form-item label="主治医生" prop="doctor">
                          <el-input v-model="item.content.registerForm.masterDoctorName" :disabled="true"/>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter= 8>
                      <el-col :span=6 :offset=10>
                        <el-form-item label="就诊医生" prop="doctor">
                          <el-select v-model="item.content.registerForm.doctorId" placeholder="请选择" >
                            <el-option
                              v-for="doctor in doctorEnum"
                              :key="doctor.id"
                              :label="doctor.name"
                              :value="doctor.id"
                              @click.native="upDoctor(doctor, item.content.registerForm)"
                              >
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                      <span style="margin-left: 10px">挂号费：{{item.content.registerForm.registerPrice}}元</span>
                    </el-row>
                    <el-row :gutter= 8>
                      <el-col :span=6 :offset=10>
                        <el-form-item label="就诊地点" prop="address">
                          <el-select v-model="item.content.registerForm.workAddressId" placeholder="请选择" :disabled="true">
                            <el-option
                              v-for="item in workAddressEnum"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id">
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row> <el-row :gutter= 8>
                      <el-col :span=6 :offset=10>
                        <el-form-item label="科室" prop="jobOffice">
                          <el-select v-model="item.content.registerForm.jobOfficeId" placeholder="请选择" >
                            <el-option
                              v-for="item in jobOfficeEnum"
                              :key="item.id"
                              :label="item.name"
                              :value="item.id"
                              >
                            </el-option>
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter= 8 v-if="item.content.registerForm.type == 1">
                      <el-col :span=6 :offset=10>
                        <el-form-item label="静息时间" prop="waitTime">
                          <el-autocomplete
                            value-key="waitTime"
                            class="inline-input"
                            v-model="item.content.registerForm.waitTime"
                            :fetch-suggestions="querySearch"
                            placeholder="请输入静息时间"
                            @select="(value)=>handleSelect(value, item.content.registerForm)"
                            style="width: 100%;"
                          >
                          <template slot-scope="{ item }">
                            <span >{{ item}}</span>
                          </template>
                          <template slot="append">分钟</template>
                          </el-autocomplete>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </el-form>
                  <!-- <div v-if="item.content.registerForm.type != 1" style="width: 100%;border: 1px solid gray;border-radius: 10px;">
                    <div v-if="item.content.registerForm.type === 2" style="padding: 10px;display: flex;flex-direction: row;justify-content: space-around;">
                      <div>
                        <p>邮寄信息</p>
                        <el-select v-model="item.content.registerForm.address" placeholder="请选择">
                          <el-option
                            v-for="address in item.content.addressListPost"
                            :key="address.id"
                            :label="address.address"
                            :value="address.id">
                          </el-option>
                        </el-select>
                        <br>
                        <br>
                        <el-button type="primary" @click="addOrUpdateAddress(item.content)">修改/添加邮寄信息</el-button>
                      </div>
                      <div >
                        <span>邮寄服务处理截止日期</span>
                        <el-date-picker
                          v-model="item.content.registerForm.postEndTime"
                          type="date"
                          placeholder="选择日期">
                        </el-date-picker>
                        <div style="border: 1px solid gray;border-radius: 10px;padding: 10px;margin-top: 10px;">
                          <span>邮寄服务节点模板选择</span>
                          <div style="padding: 10px;display: flex;flex-direction: row;justify-content: center;font-size: 16px;">
                            <div ref="template1" style="position: relative‌;border: 1px solid gray;border-radius: 10px;padding: 10px;margin-right: 3px;" >
                              <span>助理诊前 </span>
                              <el-time-picker
                                :disabled="true"
                                style="width: 120px;"
                                v-model="timeTemplate[0].gaidenceTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>医生诊中 </span>
                              <el-time-picker
                                :disabled="true"
                                style="width: 120px;"
                                v-model="timeTemplate[0].visitTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>助理缴费 </span>
                              <el-time-picker
                                :disabled="true"
                                style="width: 120px;"
                                v-model="timeTemplate[0].payTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>药房诊后 </span>
                              <el-time-picker
                                :disabled="true"
                                style="width: 120px;"
                                v-model="timeTemplate[0].drugTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>提前</span>
                              <el-input style="display: inline-block; width: 70px;margin-top: 5px;" type="Number" min=0 v-model="timeTemplate[0].warnTime" placeholder="" :disabled="true"></el-input>
                              <span>分钟提醒</span>
                              <el-button style="position: absolute‌;bottom: 5px;margin-left: 50%;margin-top: 5px;" type="primary" @click="clickTimeTemplate(1, item.content)">选择</el-button>
                            </div>
                            <div ref="template2" style="position: relative‌;border: 1px solid gray;border-radius: 10px;padding: 10px;margin-right: 3px;" >
                              <span>助理诊前 </span>
                              <el-time-picker
                                :disabled="true"
                                style="width: 120px;"
                                v-model="timeTemplate[1].gaidenceTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>医生诊中 </span>
                              <el-time-picker
                                :disabled="true"
                                style="width: 120px;"
                                v-model="timeTemplate[1].visitTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>助理缴费 </span>
                              <el-time-picker
                                :disabled="true"
                                style="width: 120px;"
                                v-model="timeTemplate[1].payTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>药房诊后 </span>
                              <el-time-picker
                                :disabled="true"
                                style="width: 120px;"
                                v-model="timeTemplate[1].drugTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>提前</span>
                              <el-input style="display: inline-block; width: 70px;margin-top: 5px;" type="Number" min=0 v-model="timeTemplate[1].warnTime" placeholder="" :disabled="true"></el-input>
                              <span>分钟提醒</span>
                              <el-button style="position: absolute‌;bottom: 5px;margin-left: 50%;margin-top: 5px;" type="primary" @click="clickTimeTemplate(2, item.content)">选择</el-button>
                            </div>
                            <div ref="template3" style="position: relative‌;border: 1px solid gray;border-radius: 10px;padding: 10px;" >
                              <span>助理诊前 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="timeTemplate[2].gaidenceTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>医生诊中 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="timeTemplate[2].visitTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>助理缴费 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="timeTemplate[2].payTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>药房诊后 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="timeTemplate[2].drugTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>提前</span>
                              <el-input style="display: inline-block; width: 70px;margin-top: 5px;" type="Number" min=0 v-model="timeTemplate[2].warnTime" placeholder=""></el-input>
                              <span>分钟提醒</span>
                              <br>
                              <el-button style="position: absolute‌;bottom: 5px;margin-left: 50%;margin-top: 5px;" type="primary" @click="clickTimeTemplate(3, item.content)">选择</el-button>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                    <div v-if="item.content.registerForm.type === 3" style="padding: 10px;">
                      <div >
                        <el-form ref="registerForm" :model="item.content.registerForm" label-width="120px"  class="guidance-form">
                          <el-row :gutter= 8>
                            <el-col :span=12>
                              <el-form-item label="代取日期" >
                                <el-date-picker
                                  v-model="item.content.registerForm.subTakeDate"
                                  type="date"
                                  placeholder="选择日期">
                                </el-date-picker>
                              </el-form-item>
                            </el-col>
                            <el-col :span=12>
                              <el-form-item label="代取时间" >
                                <el-time-picker
                                  v-model="item.content.registerForm.subTakeTime"
                                  placeholder="选择时间">
                                </el-time-picker>
                              </el-form-item>
                            </el-col>
                          </el-row>
                        </el-form>
                        <br>
                        <div style="border: 1px solid gray;border-radius: 10px;padding: 10px;margin-top: 10px;">
                          <div style="padding: 10px;display: flex;flex-direction: row;justify-content: center;font-size: 16px;">
                            <div style="border: 1px solid gray;border-radius: 10px;padding: 10px;">
                              <span>助理诊前 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="item.content.registerForm.gaidenceTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>医生诊中 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="item.content.registerForm.visitTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>助理缴费 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="item.content.registerForm.payTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>药房诊后 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="item.content.registerForm.drugTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>提前</span>
                              <el-input style="display: inline-block; width: 70px;" type="Number" min=0 v-model="item.content.registerForm.warnTime" placeholder=""></el-input>
                              <span>分钟提醒</span>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                    <div v-if="item.content.registerForm.type === 4" style="padding: 10px;">
                      <div >
                        <el-form ref="registerForm" :model="item.content.registerForm" label-width="120px"  class="guidance-form">
                          <el-row :gutter= 8>
                            <el-col :span=12>
                              <el-form-item label="代放日期" >
                                <el-date-picker
                                  v-model="item.content.registerForm.subReleaseDate"
                                  type="date"
                                  placeholder="选择日期">
                                </el-date-picker>
                              </el-form-item>
                            </el-col>
                            <el-col :span=12>
                              <el-form-item label="代放时间" >
                                <el-time-picker
                                  v-model="item.content.registerForm.subReleaseTime"
                                  placeholder="选择时间">
                                </el-time-picker>
                              </el-form-item>
                            </el-col>
                          </el-row>
                          <el-row :gutter=10>
                              <el-col :span=12>
                                <el-form-item label="代放地点" >
                                  <el-select v-model="item.content.registerForm.address" placeholder="请选择">
                                    <el-option
                                      v-for="address in item.content.addressListPost"
                                      :key="address.id"
                                      :label="address.address"
                                      :value="address.id">
                                    </el-option>
                                  </el-select>
                                </el-form-item>
                              </el-col>
                          </el-row>
                        </el-form>
                        <br>
                        <div style="border: 1px solid gray;border-radius: 10px;padding: 10px;margin-top: 10px;">
                          <div style="padding: 10px;display: flex;flex-direction: row;justify-content: center;font-size: 16px;">
                            <div style="border: 1px solid gray;border-radius: 10px;padding: 10px;">
                              <span>助理诊前 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="item.content.registerForm.gaidenceTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>医生诊中 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="item.content.registerForm.visitTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>助理缴费 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="item.content.registerForm.payTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>药房诊后 </span>
                              <el-time-picker
                                style="width: 120px;"
                                v-model="item.content.registerForm.drugTime"
                                type="time"
                                placeholder="选择时间">
                              </el-time-picker>
                              <br>
                              <span>提前</span>
                              <el-input style="display: inline-block; width: 70px;" type="Number" min=0 v-model="item.content.registerForm.warnTime" placeholder=""></el-input>
                              <span>分钟提醒</span>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

                  </div> -->
                  <div style="width: 100%;height: 20px;position: relative;margin: 10px;">
                    <el-button type="primary" style="position: absolute;right: 20px;" @click="registerFormConfirm(item.content)">
                      挂 号
                    </el-button>
                  </div>
                </div>

                <div v-if="item.content.patientTabsValue == '会员就诊记录查询'">
                  会员就诊记录查询内容
                </div>

                <div v-if="item.content.patientTabsValue == '邮寄信息添加/修改'">
                  <el-form ref="addPatientForm" :model="addPatientForm" label-width="120px" :rules="addPatientFormRules">
                    <div style="width:100%;border: 2px solid #E4E7ED;padding: 10px;">
                      <div v-for="(address, index) in item.content.addressListPost" :key="index" >
                        <el-button type="danger" icon="el-icon-delete" circle @click="deleteAddress(address, item.content.addressListPost)"></el-button>
                        <el-row :gutter="10" v-if="index != 0">
                          <el-col :span=6>
                            <el-form-item label="多址说明" prop="multiAddressDes">
                              <el-select v-model="address.multiAddressDes" placeholder="请选择" >
                                <el-option
                                  v-for="item in multiAddressDesEnum"
                                  :key="item"
                                  :label="item"
                                  :value="item"
                                  @click.native="changeMultiAddressDes(item, address)"
                                >
                                </el-option>
                              </el-select>
                            </el-form-item>
                          </el-col>
                          <el-col :span=6>
                            <el-form-item label="说明填写" v-if="address.isOtherAddress == 1" prop="multiAddressDesOther">
                              <el-input v-model="address.multiAddressDesOther"/>
                            </el-form-item>
                          </el-col>
                        </el-row>
                        <el-row :gutter="10">
                          <el-col :span="2">
                            <el-form-item label="默认地址">
                              <el-checkbox v-model="address.isDefault" @change="changeIsDefault(address, item.content.addressListPost)"></el-checkbox>
                            </el-form-item>
                          </el-col>
                          <el-col :span=8 >
                            <el-form-item label="省/市/区" prop="addressPre">
                              <el-cascader
                                size="large"
                                :options="options"
                                v-model="address.addressPre"
                                @change="handleChange"
                                :props="{ value: 'label', label: 'label'}"
                              >
                              </el-cascader>
                            </el-form-item>
                          </el-col>
                          <el-col :span=6>
                            <el-form-item label="小区" prop="addressMid">
                              <el-input v-model="address.addressMid"></el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span=8 >
                            <el-form-item label="详细地址" prop="addressInfo">
                              <el-input v-model="address.addressInfo"></el-input>
                            </el-form-item>
                          </el-col>
                        </el-row>
                        <el-row :gutter="10">
                          <el-col :span=6 >
                            <el-form-item label="收件人姓名" prop="contactName">
                              <el-input v-model="address.contactName"></el-input>
                            </el-form-item>
                          </el-col>
                          <el-col :span=8 >
                            <el-form-item label="收件人电话" prop="contactPhone">
                              <el-input v-model="address.contactPhone" type="phone" />
                            </el-form-item>
                          </el-col>
                        </el-row>
                        <el-divider></el-divider>
                      </div>
                      <el-button type="primary" @click="updateFormAddAddress(item.content)">添加地址</el-button>
                    </div>
                    <div style="width: 90%;height: 20px;position: relative;margin: 10px;">
                      <el-button type="primary" style="position: absolute;right: 20px;" @click="confirmAddress(item.content)">
                        保 存
                      </el-button>
                    </div>
                  </el-form>
                </div>
                

                </el-tab-pane>
              </el-tabs>

            </el-main>
            <el-aside width="220px">
              <el-menu
                @select="(key, keyPath) => handleMenuSelect(key, keyPath, item.content)" 
                default-active="2"
                :default-openeds="defaultOpen"
                class="el-menu-vertical-demo"
                @open="handleOpen"
                @close="handleClose">
                <el-submenu index="会员管理" >
                  <template slot="title">
                    <span style="font-weight: 600;font-size: 18px;">会员管理</span>
                  </template>
                    <el-menu-item index="会员基础信息查询" style="font-size: 14px">会员基础信息查询</el-menu-item>
                </el-submenu>
                <el-submenu index="挂号" >
                  <template slot="title">
                    <span style="font-weight: 600;font-size: 18px;">挂号</span>
                  </template>
                    <el-menu-item index="挂号" style="font-size: 14px">挂号</el-menu-item>
                </el-submenu>
                <el-submenu index="会员就诊记录查询" >
                  <template slot="title">
                    <span style="font-weight: 600;font-size: 18px;">会员就诊记录查询</span>
                  </template>
                    <el-menu-item index="会员就诊记录查询" style="font-size: 14px">会员就诊记录查询</el-menu-item>
                </el-submenu>
                <el-submenu index="邮寄/代取/贷放服务" >
                  <template slot="title">
                    <span style="font-weight: 600;font-size: 18px;">邮寄/代取/贷放服务</span>
                  </template>
                    <el-menu-item index="邮寄信息查询" style="font-size: 14px">邮寄信息查询</el-menu-item>
                    <el-menu-item index="邮寄信息添加/修改" style="font-size: 14px">邮寄信息添加/修改</el-menu-item>
                    <el-menu-item index="邮寄/代取/代放记录查询" style="font-size: 14px">邮寄/代取/代放记录查询</el-menu-item>
                </el-submenu>
              </el-menu>
            </el-aside>
          </el-container>
        </div>

      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>

import { getList as getPatientList, add, edit, del, getAllPatientList} from '@/api/patient'
import { addOrEdit } from '@/api/patientAddress'
import { regionData } from 'element-china-area-data'
import { getAllUserList, getListByDept as getUserListByDept, getLoginInfo } from '@/api/user'
import { getList as getSourceList} from '@/api/source'
import { getList, addOrUpdate, guidanceWaitingNumber} from '@/api/guidance'
import { getListByPinyinCode, queryByCodeAnDepositoryId, getListByPinyinCodeProductTime } from '@/api/drug'
import { queryDepositoryIdsByOptType } from '@/api/drugDepositoryAuth'
import Decimal from 'decimal.js';
import { addDate, getDateTime } from '@/utils/dateUtil'
import { getList as getJobOfficeList} from '@/api/jobOffice'

export default {
  name: "GuidanceRegister",
  filters: {
    birthdayTypeFilter(status) {
      const statusMap = ['', '阳', '阴']
      return statusMap[status]
    },
    statusFilter(status) {
      const statusMap = ['候诊', '就诊中', '已完成', '中止']
      return statusMap[status]
    }
  },
  data() {
    const validateName = (rule, value, callback) => {
      if (!value) callback(new Error('请输入姓名')) 
      else callback()
    }
    const validatePhone = (rule, value, callback) => {
      if (!value) callback(new Error('请输入电话')) 
      else callback()
    }
    const validateIdCard = (rule, value, callback) => {
      if (!value) callback(new Error('请输入身份证号')) 
      else callback()
    }
    const validateSex = (rule, value, callback) => {
      if (!value) callback(new Error('请选择性别')) 
      else callback()
    }
    const validateBirthday = (rule, value, callback) => {
      if (!value) callback(new Error('请选择出生日期')) 
      else callback()
    }
    const validateBirthdayType = (rule, value, callback) => {
      if (!value) callback(new Error('请选择类型')) 
      else callback()
    }
    const validateSource = (rule, value, callback) => {
      if (!value) callback(new Error('请选择来源')) 
      else callback()
    }
    const validateAddressPre = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressList) {
        if(!address.addressPre || address.addressPre.length < 3) flag = true
      }
      if (flag) callback(new Error('地址不能为空')) 
      else callback()
    }
    const validateAddressMid = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressList) {
        if(!address.addressMid || address.addressMid==='') flag = true
      }
      if (flag) callback(new Error('小区不能为空')) 
      else callback()
    }
    const validateAddressInfo = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressList) {
        if(!address.addressInfo || address.addressInfo === '') flag = true
      }
      if (flag) callback(new Error('地址不能为空')) 
      else callback()
    }
    const validateMultiAddressDes = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressList) {
        if(!address.multiAddressDes) flag = true
      }
      if (flag) callback(new Error('多址选择不能为空')) 
      else callback()
    }
    const validateMultiAddressDesOther = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressList) {
        if(address.multiAddressDes == '其他' && (!address.multiAddressDesOther || address.multiAddressDesOther === '')) flag = true
      }
      if (flag) callback(new Error('其他原因不能为空')) 
      else callback()
    }
    const validateRetailStore = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressList) {
        if(!address.retailStore) flag = true
      }
      if (flag) callback(new Error('门店不能为空')) 
      else callback()
    }
    const validateDistance = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressList) {
        if(!address.distance && address.distance == '') flag = true
      }
      if (flag) callback(new Error('公交站数不能为空')) 
      else callback()
    }
    
    const validateContactName = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressListPost) {
        if(!address.contactName && address.contactName == '') flag = true
      }
      if (flag) callback(new Error('收件人姓名不能为空')) 
      else callback()
    }
    const validateContactPhone = (rule, value, callback) => {
      var flag = false
      for (const address of this.addPatientForm.addressListPost) {
        if(!address.contactPhone && address.contactPhone == '') flag = true
      }
      if (flag) callback(new Error('收件人电话不能为空')) 
      else callback()
    }

    return {
      list: [],
      listLoading: true,
      patientList: null,
      patientListLoading: true,
      currentPage: 1,
      pageSize: 10,
      total: 0,
      curIndex: -1,
      infoVisible: false,
      addPatientformVisible: false,
      info: {},
      addPatientForm: {},
      query: {},
      dialogTitle: '添加来源',
      depts:[],
      editableTabsValue: '会员查询',
      editableTabs: [],
      patientTabsValue: '',
      patientTabs: [],
      sourceEnum: [],
      sexEnum: ["男", "女"],
      userEnum: [],
      doctorEnum: [],
      patientEnum: [],
      jobOfficeEnumAll: [],
      jobOfficeEnum: [],
      workAddressEnum: [],
      waitTimeEnum: ['5', '10', '15', '20', '30', '60', '120'],
      typeEnum: [{id: 1, name: '店面就诊'},{id: 2, name: '邮寄'},{id: 3, name: '代取'},{id: 4, name: '代放'}],
      options: regionData,
      birthdayTypeEnum:[{id: 1, name: '公历'}, {id: 2, name: '农历'}],
      multiAddressDesEnum: ["临时居住", "子女居所", "邮寄用地址", "其他"],
      deptEnum: ['劳动店', '永春店'],
      introducerDisable: true,
      defaultOpen: ['会员管理', '挂号', '会员就诊记录查询', '邮寄/代取/贷放服务'],
      addPatientFormRules: {
        name: [{ required: true, trigger: 'blur', validator: validateName }],
        phone: [{ required: true, trigger: 'blur', validator: validatePhone }],
        idCard: [{ required: true, trigger: 'blur', validator: validateIdCard }],
        sex: [{ required: true, trigger: 'blur', validator: validateSex }],
        birthday: [{ required: true, trigger: 'blur', validator: validateBirthday }],
        birthdayType: [{ required: true, trigger: 'blur', validator: validateBirthdayType }],
        source: [{ required: true, trigger: 'blur', validator: validateSource }],
        addressPre: [{ required: true, trigger: 'blur', validator: validateAddressPre }],
        addressMid: [{ required: true, trigger: 'blur', validator: validateAddressMid }],
        addressInfo: [{ required: true, trigger: 'blur', validator: validateAddressInfo }],
        multiAddressDes: [{ required: true, trigger: 'blur', validator: validateMultiAddressDes }],
        multiAddressDesOther: [{ required: true, trigger: 'blur', validator: validateMultiAddressDesOther }],
        retailStore: [{ required: true, trigger: 'blur', validator: validateRetailStore }],
        distance: [{ required: true, trigger: 'blur', validator: validateDistance }],
        contactName: [{ required: true, trigger: 'blur', validator: validateContactName }],
        contactPhone: [{ required: true, trigger: 'blur', validator: validateContactPhone }],
      },
      timeTemplate: [
        {gaidenceTime: getDateTime(14, 10, 10), visitTime: getDateTime(14, 10, 10), payTime: getDateTime(14, 10, 10), drugTime: getDateTime(14, 10, 10), warnTime: 20}, 
        {gaidenceTime: getDateTime(14, 10, 10), visitTime: getDateTime(14, 10, 10), payTime: getDateTime(14, 10, 10), drugTime: getDateTime(14, 10, 10), warnTime: 20},
        {gaidenceTime: undefined, visitTime: undefined, payTime: undefined, drugTime: undefined, warnTime: undefined}
      ]
     
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      var loginInfo = this.$store.getters.userInfo.loginInfo
      var deptId = loginInfo.loginDept.deptId
      // var workAddressId = loginInfo.loginWorkAddress.id
      var jobOfficeId = loginInfo.loginJobOffice?loginInfo.loginJobOffice.jobOfficeId:undefined
      console.log("loginInfo", loginInfo)

      this.getPatientList({})

      guidanceWaitingNumber({deptId: deptId, workAddressId: undefined, jobOfficeId: jobOfficeId}).then(res=> {
        this.reports = res.data
      })
      getSourceList().then(sourceRes=>{
        this.sourceEnum = sourceRes.data
      })
      getAllPatientList().then(res=>{
        console.log("patient res:", res)
        this.patientEnum = res.data
      })
      getAllUserList().then(res=>{
        console.log("user res:", res)
        this.userEnum = res.data
      })
    },
    clickCurPage(val){
      this.currentPage = val
      this.fetchData()
    },
    getInfo(row) {
      this.info = row
      this.infoVisible = true
    },
    update(row) {
      this.reset()
      this.dialogTitle = '修改来源'
      this.form = JSON.parse(JSON.stringify(row))
      this.formVisible = true
    },
    
    cancel() {
      this.formVisible = false
    },
    reset(){
      this.form = {}
    },
    removeTab(targetName) {
      console.log(targetName)
      let tabs = this.editableTabs;
      let activeName = this.editableTabsValue;
      if (activeName === targetName) {
        tabs.forEach((tab, index) => {
          if (tab.name === targetName) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab.name;
            }
          }
        });
      }
      this.editableTabsValue = activeName;
      this.editableTabs = tabs.filter(tab => tab.name !== targetName);
      console.log('this.editableTabs', this.editableTabs)
      if(this.editableTabs.length == 0) {
        this.editableTabsValue = '会员查询'
      }
    },
    removePatientTab(targetName, patient) {
      let tabs = patient.patientTabs;
      let activeName = patient.patientTabsValue;
      if (activeName === targetName) {
        tabs.forEach((tab, index) => {
          if (tab.name === targetName) {
            let nextTab = tabs[index + 1] || tabs[index - 1];
            if (nextTab) {
              activeName = nextTab.name;
            }
          }
        });
      }
      patient.patientTabsValue = activeName;
      patient.patientTabs = tabs.filter(tab => tab.name !== targetName);
    },
    search() {
      this.getPatientList({name: this.query.name})
    },    
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //  get patient list page function
    getPatientList(params) {
      this.patientListLoading = true
      params.currentPage = this.currentPage
      params.pageSize = this.pageSize 
      getPatientList(params).then(res=>{
        this.$set(this, 'patientList', res.data.records)
        console.log(this.patientList)
        this.patientList.forEach(item=>{
          item.age = new Date().getFullYear() - item.birthday.substring(0,4)
          item.addressList.forEach(address=>{
            var addressPreArr = address.address.split('|||')
            address.addressPre = [addressPreArr[0], addressPreArr[1], addressPreArr[2]]
            this.$set(address, 'addressMid', addressPreArr[3])
            this.$set(address, 'addressInfo', addressPreArr[4])
            address.isDefault = address.isDefault == "1"
          })
        })
        this.patientListLoading = false
      }).catch(err=>{
        console.log("err")
        console.log(err)
        this.patientListLoading = false
      })
      
    },
   
    handleChange (address) {
      this.$set(this.addPatientForm, 'addressPre', address)
    },
    addAddress() {
      this.addPatientForm.addressList.push({})
    },
    deleteAddress(address, list) {
      list.splice(list.indexOf(address), 1);
    },
    updateFormAddAddress(updateForm) {
      updateForm.addressListPost.push({})
      console.log(updateForm.addressListPost)
    },
    changeBirthday() {

    },
    changeMultiAddressDes(item, address) {
      if(item == '其他')  {
        this.$set(address, 'isOtherAddress', 1)
      } else {
        this.$set(address, 'isOtherAddress', 0)
      }
    },
    confirm() {
      this.$refs.addPatientForm[0].validate(valid => {
        if (valid) {
          console.log(this.addPatientForm)
          this.addPatientForm.addressList.forEach(address=>{
            address.address = address.addressPre[0] + ' ' + address.addressPre[1] + ' ' + address.addressPre[2] + ' ' + address.addressMid + ' ' + address.addressInfo
          })
          add(this.addPatientForm).then(res=>{
            console.log(res)
            this.$message({
              message: '添加成功',
              type: 'success'
            })
            this.editableTabsValue = "1"
          }).catch(err=>{
            console.log(err)
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    updateConfirm(updateForm) {
      // this.$refs.updatePatientForm[0].validate(valid => {
      //   if (valid) {
          console.log(updateForm)
          updateForm.addressList.forEach(address=>{
            address.address = address.addressPre[0] + ' ' + address.addressPre[1] + ' ' + address.addressPre[2] + ' ' + address.addressMid + ' ' + address.addressInfo
          })
          edit(updateForm).then(res=>{
            console.log(res)
            this.$message({
              message: '修改成功',
              type: 'success'
            })
            this.editableTabsValue = "1"
          }).catch(err=>{
            console.log(err)
          })
        // } else {
        //   console.log('error submit!!')
        //   return false
        // }
      // })
    },
    optionPatient(patient) {
      var list = this.editableTabs.filter(item => item.name == patient.code)
      this.initPatientVisitData(patient, list)
    },

    initPatientVisitData(patient, list) {
      if(list.length != 0) {
        this.editableTabsValue = patient.code
        return
      }
      var loginDept = this.$store.getters.userInfo.loginInfo.loginDept
      getUserListByDept(loginDept.deptId).then(res=>{
        console.log("res", res)
        this.doctorEnum = res.data
      })
      getJobOfficeList().then(res=>{
        this.jobOfficeEnumAll = res.data
      })
      this.$set(patient, 'patientTabsValue', '挂号')
      this.$set(patient, 'patientTabs', [{
        title: '挂号',
        name: '挂号',
        content: {}
      }])
      this.$set(patient, 'visitActiveName', '')
      patient.addressList.forEach(addressItem => {
        addressItem.address = addressItem.address.replaceAll('|||', ' ')
      })
      var addressListPost = JSON.parse(JSON.stringify(patient.addressList.filter(address => address.type == 2)))
      if(addressListPost.length == 0) {
        addressListPost.push({isDefault: true})
      }
      this.$set(patient, 'addressListPost', addressListPost)
      patient.addressList = patient.addressList.filter(address => address.type == 1)
      var defaultAddressPost = addressListPost.filter(address => address.isDefault)
      this.$set(patient, 'registerForm', {
        type: 1, 
        address: defaultAddressPost && defaultAddressPost.length != 0 ? defaultAddressPost[0] : undefined,
        postEndTime: new Date()
      })
      console.log('patient.registerForm',patient.registerForm)
      this.editableTabs.push({
        title: patient.name,
        name: patient.code,
        content: patient
      })
      this.addPatientForm = patient
      this.editableTabsValue = patient.code
    },

    /** patient detail page function */
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    handleMenuSelect(key, keyPath, patient) {
      console.log(patient)
      var tabValue = keyPath[0]
      console.log(tabValue)
      this.$set(patient, 'visitActiveName', keyPath[1])
      var list = patient.patientTabs.filter(item => item.name == tabValue)
      if(list.length != 0) {
        patient.patientTabsValue = tabValue
        return
      }

      patient.patientTabs.push({
        title: tabValue,
        name: tabValue,
        content: {}
      })
      patient.patientTabsValue = tabValue
    },
    upDoctor(value, form) {
      console.log(value)
      this.$set(form, 'registerPrice', value.registerPrice)
      getLoginInfo(value.id).then(res=> {
        var loginInfo = res.data.userDeptWorkAddressJobOffice
        this.jobOfficeEnum = this.getJobOfficeEnum(loginInfo.jobOfficeId)
        this.$set(form, 'jobOfficeId', loginInfo.jobOfficeId)
        this.$set(form, 'workAddressId', loginInfo.workAddressId)
        this.workAddressEnum = [{id: loginInfo.workAddressId, name: loginInfo.workAddressName}]
      })
    },
    getJobOfficeEnum(jobOfficeId) {
      return this.jobOfficeEnumAll.filter(jobOffice => jobOffice.id == jobOfficeId)
    },
    querySearch(queryString, cb) {
      // 调用 callback 返回建议列表的数据
      cb(this.waitTimeEnum);
    },
    handleSelect(value, form) {
      this.$set(form, 'waitTime', value)
    },
    registerFormConfirm(patient) {
      var form = patient.registerForm
      form.patientId = patient.id
      var loginDept = this.$store.getters.userInfo.loginInfo.loginDept
      form.deptId = loginDept.deptId
      this.$refs.registerForm[0].validate(valid => {
        if (valid) {
          console.log(form)
          addOrUpdate(form).then(res=>{
            console.log(res)
            this.$message({
              message: '添加/修改成功',
              type: 'success'
            })
            this.removeTab(patient.code)
          }).catch(err=>{
            console.log(err)
          })
        }
      })
      console.log("registerForm", patient.registerForm)
    },
    updateVisitType(item, patient) {

    },
    addOrUpdateAddress(patient) {
      this.$set(patient, 'patientTabsValue', '邮寄信息添加/修改')
      var list = patient.patientTabs.filter(item => item.name == '邮寄信息添加/修改')
      if(list.length != 0) {
        patient.patientTabsValue = '邮寄信息添加/修改'
        return
      }
      patient.patientTabs.push({
        title: '邮寄信息添加/修改',
        name: '邮寄信息添加/修改',
        content: {}
      })

    },
    confirmAddress(patient) {
      patient.addressListPost.forEach(address=>{
        address.patientId = patient.id
        address.address = address.addressPre[0] + '|||' + address.addressPre[1] + '|||' + address.addressPre[2] + '|||' + address.addressMid + '|||' + address.addressInfo
        address.type = 2
        if(address.isDefault) {
          address.isDefault = 1
        } else {
          address.isDefault = 0
        }
      })
      addOrEdit({addressList: patient.addressListPost}).then(res=> {
        console.log(res)
        this.$message.success("保存成功")
        patient.addressListPost.forEach(addressItem => {
          addressItem.address = addressItem.address.replaceAll('|||', ' ')
        })
        this.removePatientTab('邮寄信息添加/修改', patient);
      })
    },
    changeIsDefault(address, addresslist) {
      addresslist.forEach(item=> {
        this.$set(item, 'isDefault', false)
      })
      this.$set(address, 'isDefault', true)
    },
    clickTimeTemplate(type, patient) {
      if(type == 1) {
        patient.registerForm.gaidenceTime = this.timeTemplate[0].gaidenceTime
        patient.registerForm.visitTime = this.timeTemplate[0].visitTime
        patient.registerForm.payTime = this.timeTemplate[0].payTime
        patient.registerForm.drugTime = this.timeTemplate[0].drugTime
        patient.registerForm.warnTime = this.timeTemplate[0].warnTime
        this.$refs.template1[0].style.border = '3px solid black'
        this.$refs.template2[0].style.border = '1px solid gray'
        this.$refs.template3[0].style.border = '1px solid gray'
      } else if(type == 2) {
        patient.registerForm.gaidenceTime = this.timeTemplate[1].gaidenceTime
        patient.registerForm.visitTime = this.timeTemplate[1].visitTime
        patient.registerForm.payTime = this.timeTemplate[1].payTime
        patient.registerForm.drugTime = this.timeTemplate[1].drugTime
        patient.registerForm.warnTime = this.timeTemplate[1].warnTime
        this.$refs.template2[0].style.border = '3px solid black'
        this.$refs.template1[0].style.border = '1px solid gray'
        this.$refs.template3[0].style.border = '1px solid gray'
      } else if(type == 3) {
        this.$set(patient.registerForm, 'gaidenceTime', this.timeTemplate[2].gaidenceTime)
        this.$set(patient.registerForm, 'visitTime', this.timeTemplate[2].visitTime)
        this.$set(patient.registerForm, 'payTime', this.timeTemplate[2].payTime)
        this.$set(patient.registerForm, 'drugTime', this.timeTemplate[2].drugTime)
        this.$set(patient.registerForm, 'warnTime', this.timeTemplate[2].warnTime)
        this.$refs.template3[0].style.border = '3px solid black'
        this.$refs.template1[0].style.border = '1px solid gray'
        this.$refs.template2[0].style.border = '1px solid gray'
      }
    }
    
  }
}
</script>


<style>
  .el-aside {
    width: 20%;
    text-align: center;
  }
  
  .el-main {
    width: 80%;
    text-align: left;
  }
  
  body > .el-container {
    margin-bottom: 40px;
  }
  .main-head-title {
    font-size: 14px;
  }
  .el-table .cell {
    white-space: pre-line;
  }
  
</style>